<template>
	<view class="pad-lr-30 bgfff">
	<view class="display view_view pad-tb-40">
		<view class="left_view">
			地区
		</view>
		<view class="right_view display-sb align-items" @click="selenowaddress">
				<view class="ml10 text-align-right fontSize-28">{{info.province||'选择所在省、市、区'}}</view>
			<image src="/static/img/icon_youjiantou_.png" class="you_icon ml10" mode=""></image>
		</view>
	</view>
	<view class="display-sb view_view pad-tb-40">
		<view class="left_view">
			详细地址
		</view>
		<view class="right_view display-sb align-items">
			<view class="display align-items">
				<input type="text" class="ml10 fontSize-28" v-model="info.address" placeholder="请填写详细地址" />
			</view>
		</view>
	</view>
	<view class="display-sb view_view pad-tb-40">
		<view class="left_view">
			门店名称
		</view>
		<view class="right_view display-sb align-items">
			<view class="display align-items">
				<input type="text" class="ml10 fontSize-28" v-model="name" placeholder="请填写门店名称" />
			</view>
		</view>
	</view>
	<view class="display-sb view_view pad-tb-40">
		<view class="left_view">
			联系方式
		</view>
		<view class="right_view display-sb align-items">
			<view class="display align-items">
				<input type="number" maxlength="11" class="ml10 fontSize-28" v-model="phone" placeholder="请填写联系方式" />
			</view>
		</view>
	</view>
	<view class="display-sb view_view pad-tb-40">
		<view class="left_view">
			微信号
		</view>
		<view class="right_view display-sb align-items">
			<view class="display align-items">
				<input type="text" class="ml10 fontSize-28" v-model="wx_number" placeholder="请填写微信号" />
			</view>
		</view>
	</view>
	<view class="mar-top-30 fontSize-30">logo主图</view>
	<view class="pad-tb-30">
		<o-upload :imageHeight="200" :maxFile="1" :list="image1"  @success="successimg3" @remove="remove3"></o-upload>
	</view>
	<view class="mar-top-30 fontSize-30">营业执照</view>
	<view class="pad-tb-30">
		<o-upload :imageHeight="200" :maxFile="1" :list="business1"  @success="successimg1" @remove="remove1"></o-upload>
	</view>
	<view class="mar-top-30 fontSize-30">门店照片</view>
	<view class="pad-tb-30">
		<o-upload :imageHeight="200" :maxFile="9"  :list="cover1" @success="successimg2" @remove="remove2"></o-upload>
	</view>
	<view class="baocun_btn poFi text-align-center col-f fontSize-32 radius-40" @click="addressbtn">
		保存
	</view>
	<!-- 地址选择弹窗 -->
	<my-address :showPop="showdate" @confirm_shop="sureAddress" @cancel="cancel"></my-address>
	</view>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import {getshopInfo,saveShop,ApitestUrl} from '@/utils/api'
import { onLoad } from '@dcloudio/uni-app';
onLoad(()=>{
	_merchants_view()
})
const _merchants_view =() =>{
	getshopInfo().then(res=>{
		if(res.code==1){
			info.value.address = res.data.shop.address
			info.value.province = res.data.shop.city_text
			info.value.city = res.data.shop.city
			name.value = res.data.shop.name
			phone.value = res.data.shop.phone
			wx_number.value = res.data.shop.wx_number
			cover.value = res.data.shop.images
			business.value = [res.data.shop.business_image]
			cover1.value = res.data.shop.images_text
			business1.value = [res.data.shop.business_image_text]
			image.value = [res.data.shop.image]
			image1.value = [res.data.shop.image_text]
		}
	})
}
const info = ref({
	province:'',
	city:'',
	address:''
})
const id = ref()
const name = ref()
const phone = ref()
const wx_number = ref()
const cover = ref()
const business = ref()
const cover1 = ref()
const business1 = ref()
const showdate = ref(false)
const image = ref()
const image1 = ref()
const selenowaddress =() =>{
	showdate.value = true
}
const successimg1 =(e,fileList) =>{
	console.log(e,fileList,18)
	let imglist = []
	let imglist1 = []
	fileList.forEach(item=>{
		if(item.response){
			imglist.push(JSON.parse(item.response).data.file.url)
			imglist1.push(JSON.parse(item.response).data.file.full_url)			
		}else{
			imglist.push(item.url)
			imglist1.push(item.url)
		}
		business.value = imglist
		business1.value = imglist1
	})
}
const aaa = ref()
const successimg2 =(e,fileList) =>{
	console.log(fileList,18)
	let imglist = []
	fileList.forEach(item=>{
		if(item.response){
				imglist.push(JSON.parse(item.response).data.file.url)
		}else{
			imglist.push(item.url)
		}
			cover.value=imglist
	})
	console.log(cover.value,19)
}
const successimg3 =(e,fileList) =>{
	let imglist = []
	let imglist1 = []
	fileList.forEach(item=>{
		if(item.response){
			imglist.push(JSON.parse(item.response).data.file.url)
			imglist1.push(JSON.parse(item.response).data.file.full_url)			
		}else{
			imglist.push(item.url)
			imglist1.push(item.url)
		}
		image.value = imglist
		image1.value = imglist1
	})
}
const remove1 = (e) =>{
	business.value=[]
	business1.value=[]
}
const remove2 = (e) =>{
	cover.value.forEach((item,index)=>{
		if(e.response){
			if(JSON.parse(e.response).data.file.url==item){
				cover.value.splice(index,1)
			}
		}else{
			if(item==e.url){
				cover.value.splice(index,1)
			}
		}
	})
	console.log(cover.value)
}
const remove3 = (e) =>{
	image.value=[]
	image1.value=[]
}
const sureAddress = (e,a) =>{
	console.log(e,a)
	info.value.province = e
	info.value.city = a
	showdate.value = false
}
const cancel = () =>{
	showdate.value = false
}
const addressbtn =() =>{
	saveShop({
		city:info.value.city.join(','),
		name:name.value,
		phone:phone.value,
		wx_number:wx_number.value,
		images:cover.value.join(','),
		image:image.value.join(','),
		business_image:business.value.join(','),
		address:info.value.address
	}).then(res=>{
		uni.showToast({
			title:res.msg,
			icon:'none'
		})
		if(res.code==1){
			uni.$emit('updatashopinfo')
			setTimeout(()=>{
				uni.navigateBack({delta:1})
			},1500)
		}
	})
}
</script>

<style lang="scss">
page{
	padding-bottom: 200rpx
}
@import 'shopinfo.scss';
</style>
